package com.desire.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Description:
 * @Author: littleDesire
 * @Date: 2022-06-11 11:17
 * @Version: 1.0
 */
public class ErpGlobalFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        String first = request.getHeaders().getFirst("x-token");

        System.out.println("x-token: " + first);

        return chain.filter(exchange);
    }

    /**
     *  返回值越大，优先级越高 （默认值为0）
     * @return
     */
    @Override
    public int getOrder() {
        return 0;
    }
}

